# encoding: utf-8
import re

from openpyxl import load_workbook

wb = load_workbook(r'F:\Personal Files\内江师范学院\_课程&作业&资料\软件测试、软件构造\软件构造\题目表格.xlsx')
sheet = wb.worksheets[0]

# 初始化题号(解决题目没有题号的情况)
question_no = 1
# 遍历表格
for row_num in range(1, 200):
    question = sheet.cell(row=row_num, column=1).value
    option_A = sheet.cell(row=row_num, column=2).value
    option_B = sheet.cell(row=row_num, column=3).value
    option_C = sheet.cell(row=row_num, column=4).value
    option_D = sheet.cell(row=row_num, column=5).value
    # 通过题目最后的字母获取
    answer = ""
    for c in reversed(question):
        if c.isalpha():
            answer += c
        else:
            break
    answer = answer[::-1]
    # 把题目中的答案去掉
    question = question.strip().replace(answer, "")

    # 通过括号获取答案
    if len(answer) == 0:
        # 获取括号中的内容
        answer = re.findall(r'[（](.*?)[）]', question)
        # 中文括号里没有找英文括号
        if len(answer) == 0:
            answer = re.findall(r'[(](.*?)[)]', question)
        # 英文括号也没有找下划线
        if len(answer) == 0:
            answer = re.findall(r'[_](.*?)[_]', question)
        # 把题目中的答案去掉
        question = question.lstrip().replace(str(answer[-1]),"")
        answer = answer[-1]

    # # 检查有没有题号
    # if not question[0].isdigit():
    #     question = f"{question_no}.{question}"
    #     question_no += 1
    print(question)
    # 检查是不是选择题
    if option_B is not None:
        print(option_A)
        print(option_B)
        print(option_C)
        print(option_D)
    # 检查是不是判断题
    if answer[-1].strip() == "√":
        answer = "对"
    elif answer[-1].strip() == "×":
        answer = "错"
    # print(f"答案：{answer[-1].strip().strip('_')}")
    print(f"答案：{answer.strip().strip('_')}")